package com.micro.glszh.stat.utils;

import com.micro.glszh.stat.domain.SysUser;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局user
 *
 * @author gaopengfei
 * @date 2020-04-30
 */
public class LocalUserUtils {
    private static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();

    public static void set(SysUser sysUser, Integer scope) {
        Map<String, Object> map = new HashMap<>();
        map.put("user", sysUser);
        map.put("scope", scope);
        LocalUserUtils.threadLocal.set(map);
    }

    public static void clear() {
        LocalUserUtils.threadLocal.remove();
    }

    public static SysUser getUser() {
        Map<String, Object> map = LocalUserUtils.threadLocal.get();
        SysUser user = (SysUser) map.get("user");
        return user;
    }

    public static Integer getScope() {
        Map<String, Object> map = LocalUserUtils.threadLocal.get();
        Integer scope = (Integer) map.get("scope");
        return scope;
    }
}
